package com.bishe.demo.modules.hotel.hotelPolicy.controller;

import com.bishe.demo.modules.common.entity.ResultEntity;
import com.bishe.demo.modules.hotel.hotelPolicy.entity.Policy;
import com.bishe.demo.modules.hotel.hotelPolicy.service.PolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class PolicyController {
    @Autowired
    private PolicyService policyService;

    @PostMapping(value = "/policy",consumes = "application/json")
    public ResultEntity<Policy> insertPolicy(@RequestBody Policy policy){
        return policyService.insertPolicy(policy);
    }

    @GetMapping(value = "/policy/{hotelId}")
    public Policy getPolicyByHotelId(@PathVariable int hotelId){
        return policyService.getPolicyByHotelId(hotelId);
    }

    @PutMapping(value = "/policy",consumes = "application/json")
    public ResultEntity<Policy> updatePolicy(@RequestBody Policy policy){
        policyService.updatePolicy(policy);
        return policyService.insertPolicy(policy);
    }
}
